home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
sampler4.arc
/
IO.SAC
< prev
next >
Wrap
Text File
|
1985-08-30
|
29KB
|
841 lines
ON ECHO
!*******************************************************************!
! !
! Data Input and Output in SORITEC Sampler !
! (Chapters 3 and 4) !
! !
!*******************************************************************!
!
! SORITEC Sampler can import and export data in a number of formats.
! In addition, Sampler supports a complete databanking facility that
! allows you to maintain all of SORITEC's data types, plus GROUPS and
! equations with a simple set of commands. This demonstration
! illustrates most of these capabilities.
!
!*******************************************************************!
! !
! Keyboard Entry !
! (Section 3.4) !
! !
!*******************************************************************!
!
! Data are entered directly from the terminal keyboard with the
! FILL command, e.g.,
!
FILL short_series_a 4 6 8 3 6 8 3 5 8 2
!
! If no USE command is in effect, SORITEC Sampler counts the number of
! observations associated with the variable and sets the USE period
! accordingly. Let's enter the USE command with no arguments to
! see how Sampler defined the USE period for the previous FILL command.
!
USE
!
! You can use a standard FORTRAN repeat operator to enter consecutive
! numbers with the same value, e.g.,
!
FILL short_series_b 5 3*6 4 9.3 2*10.1 8 14
!
! If you enter more observations for a variable than defined by
! the current USE period, SORITEC Sampler returns an error and
! ignores the command, e.g.,
!
FILL too_long 3 6 8 4 6 7 3 6 9 5 3 8
!
! You must change the USE period to accommodate the number of
! observations when there are more data to be entered than allowed
! by the current USE period. Any periodicity of time series,
! included undated data types, may be entered from the terminal.
!
USE 1980m1 1980m12
FILL too_long 3 6 8 4 6 7 3 6 9 5 3 8
!
! Normally, Sampler generates an error and ignores the command when
! too few data items are entered.
!
FILL too_short 4 5 7 3 4
!
! However, if you enable the RAGGED option with the ON RAGGED command,
! data series shorter than the current USE period are accepted. The
! remaining observations are assigned MISSING values.
!
ON RAGGED
FILL too_short 4 5 7 3 4
OFF RAGGED
PRINT too_long too_short
!
! The FILL command is commonly used to enter short data series or to
! extend or revise existing data series. For example, extending the
! variable "too_short" be three observations is easy.
!
USE 1980m6 1980m8
FILL new_data 4 5 8
REVISE too_short = new_data
USE 1980m1 1980m12
PRINT too_long too_short
!
! More information about data revision in SORITEC Sampler is given
! in the file, "revise.sac".
!
!*******************************************************************!
! !
! SAL File Input and Output !
! (Section 3.1) !
! !
!*******************************************************************!
!
! SORITEC SAL files are the most convenient way to transfer data into
! Sampler. SAL files are simply unformatted flat-ASCII files that
! have special headers and trailers that identify the USE period
! and variable names. A sample SAL file is shown below.
!
! USE 1978 1983
! READ total_population
! 222585.0000 225055.0000 227738.0000 230019.0000
! 232309.0000 234496.0000
! ;
! READ male_population
! 108424.0000 109584.0000 110874.0000 111984.0000
! 113105.0000 114179.0000
! ;
! END
! READ female_population
! 114161.0000 115472.0000 116864.0000 118034.0000
! 119204.0000 120317.0000
! ;
! END
!
! To read a SAL file, simply enter READ(filename). The header
! informs Sampler what the USE period of the data is and what
! the variable names are. The file above is stored under the name
! "popdata.sal" on this demonstration diskette, which is assumed
! to be in the a: drive. To read it, simply enter:
!
READ('a:popdata')
!
! There are several things to note about this command:
! (1) The .SAL extension is omitted from the filename argument.
! Any file that is read with the READ command must have a
! .SAL extension. Including the file extension will generate
! an error.
! (2) If the file is in other than the current directory, the
! filename must be enclosed within single quotes.
! (3) In executing the READ statement, SORITEC Sampler reads
! data until it encounters an END statement. A subsequent
! READ of the same file continues reading the file until
! another END statement is found.
!
! In the example above, SORITEC Sampler has read "total_population"
! and "male_population" into the workspace. You can find this out
! by entering the command SYMBOLS, e.g.,
!
SYMBOLS
!
! Let's READ in "female_population" now with another READ command.
!
READ('a:popdata')
SYMBOLS
!
! A SAL file can contain as many blocks, delimited by END statements
! as disk space permits. Also, SAL files can contain variables of
! mixed periodicities. Simply insert a USE statement before the READ
! statement that identifies the variable.
!
! Data may be written to files in SAL file format with the PUNCH command.
! This is particularly useful if you wish to export data to another
! SORITEC on another type of computer since data transfer
! is essentially transparent and yet the data are in ASCII format.
!
! PUNCH only writes to a file named PUNCH1.SAL in the current directory.
! Unlike file naming in the READ command, you cannot direct output to any
! other file name. Use the DOS REN command to change the file name after
! terminating SORITEC Sampler. Note that if a file PUNCH1.SAL already
! exists on your directory, SORITEC Sampler will delete it and open a new
! file PUNCH1.SAL. The PUNCH command will be superceded by more general
! output commands in later versions of SORITEC.
!
! Let's say we want to write a SAL file containing (1) the difference
! between female and male populations, and (2) the ratio of female to
! total population. First, make the appropriate calculations.
!
pop_difference = female_population - male_population
female_proportion = female_population/total_population
!
! Now write out a SAL file called to the current directory. If you
! are running Sampler off a hard disk system, the file will be written
! to the directory which contains the Sampler program. If you are
! running the program on a floppy disk system, the file will be written
! on the a: drive. We'll only demonstrate the PUNCH command with a
! small amount of data since space is limited if you are running Sampler
! on a double-floppy system.
!
PUNCH pop_difference female_proportion
!
! Note that SORITEC Sampler leaves the SAL file open for
! additional data output until you PUNCH to another file or the
! SORITEC Sampler is terminated. When the file is closed, an END
! statement is appended to it. No intervening END statements are
! inserted into the file, for example, after each PUNCH statement
! is executed. Remember, if PUNCH1.SAL already exists on the current
! directory, it is deleted before the data associated with the PUNCH
! command are written. Unlike SORITEC Databanks, SAL files can only
! be "managed" by DOS commands.
!
!*******************************************************************!
! !
! DIF File Input and Output !
! (Section 3.2) !
! !
!*******************************************************************!
!
! Data can be transferred between most population PC packages that
! support the DIF file format.
!
! For DIF file input, use the READDIF command. Although the command syntax
! is similar to the READ command, there are some important differences.
! (1) READDIF does not interpret dates in the DIF file so you
! must specify the USE period for the data before you enter
! the READDIF command.
! (2) If variable names are not in the DIF file, they must be
! entered in the command line.
!
! As an example, consider the DIF file generated by LOTUS' Translate
! utility. If you have a copy of LOTUS, this worksheet from which the
! data were translated is in "POPNEW.WKS". The worksheet consists of
! two labelled columns containing the variables "popciv" and "poh" for
! the period 1982m1 to 1983m12. The worksheet has been translated to a
! file named "popnew.dif".
!
! To import the data, set the USE period:
!
USE 1982m1 1983m12
!
! then read the DIF file with the command:
!
READDIF('a:popnew')
!
! If the DIF file was not labelled, the command line would be:
!
! READDIF('a:popnew') popciv poh
!
!
! Data are exported in DIF file format using the PUNCHDIF command.
! For example, if you wanted to export the 1982 values of "poh" and
! "popciv" to the file "popdata.dif", the command would be:
!
USE 1982m1 1982m12
PUNCHDIF('a:popdata') poh popciv
!
! If you have a copy of LOTUS, use the Translate utility to convert
! the file into a worksheet. Note that LOTUS translates the dates into
! a variable called "time" and writes these data to the first column
! (or row) of the worksheet. When dates are in the DIF file, SORITEC
! Sampler assigns MISSING values to "time". DIF files are managed by
! DOS, so use DOS commands to delete, copy, rename, etc. the files.
!
!*******************************************************************!
! !
! Formatted Input and Output !
! (Section 3.2) !
! !
!*******************************************************************!
!
! Formatted input and output is similar to that in FORTRAN programs.
! The format of the data that are to be imported or exported are
! specified in a FORMAT statement, identified by a statement number.
! Data are read or written in the desired format by refering to the
! statement number that defines that format. Data may be read or
! written in formatted form either to files or the terminal with the
! READ and WRITE commands.
!
! Note that you may WRITE data to an output device without refering
! to a FORMAT statment number. In this case, data are written as
! they are with the PRINT command, e.g., writing "male_population"
! and "female_population" to the terminal results in the following
! output:
!
USE 1978 1983
WRITE male_population female_population
!
! Formatted input and output is demonstrated in an example whereby
! we wish to read from a file data in tabular form. The data are
! defined as in the following table.
!
! 1st row --> KEY MACROECONOMIC INDICATORS
!
! Year Gross Nat. Product Civ. Labor Force Corporate Profits
! (billions of $) (millions of persons) (billions of $)
! 1980 2631.7 106.940 149.829
! 1981 2957.8 108.670 140.009
! 1983 3069.3 110.205 104.843
! 1984 3304.8 111.551 127.414
!
! ^
! |
! 1st column
!
! You should always leave a blank line at the end of the file to avoid
! spurious READ errors.
!
! To read the data, first set up the format statement. Use of integer
! (I) format is not advised for input so the year data should be read
! in as REAL.
!
100 FORMAT(///4(/f4.0,8x,f6.1,15x,f6.0,15x,f6.0))
!
! Next, define the USE period for the data.
!
USE 1980 1983
!
! When importing data with a formatted READ, SORITEC Sampler normally
! expects to read in one observation at a time, re-using the format
! from the start for each observation. If you are putting more than
! one observation on each input record, or you need to skip some initial
! input records, you need to enable the STREAMIO global option using
! the ON STREAMIO command. This causes SORITEC to compute the total
! number of data points to be read (i.e., the number of observations
! multiplied by the number of variables), and then read the entire
! mass of data in a single formatted READ, reusing the format only as
! and when necessary.
!
ON STREAMIO
!
! Now import the data with the READ command. We'll read the data
! directly from this command file to save space on the demonstration
! diskette.
!
READ(100) year gnp clf profits
KEY MACROECONOMIC INDICATORS
Year Gross Nat. Product Civ. Labor Force Corporate Profits
(billions of $) (millions of persons) (billions of $)
1980 2631.7 106940 149829
1981 2957.8 108670 140009
1983 3069.3 110205 104843
1984 3304.8 111551 127414
!
! Print out the values of the variables for verification.
!
PRINT year gnp clf profits
!
! Let's add population to the table and print it out row-wise rather then
! column-wise. We'll write the table to the terminal instead of disk to
! save some room.
!
! Set up the format statement.
!
200 FORMAT(//10x,'Key Macroeconomic Indicators Including Population'/)
201 FORMAT(19x,4(8x,f5.0)/18x,4(9x,4('-')))
202 FORMAT(1x,'Gross Nat. Product',4(3x,f10.1)/' (billions of $)'/)
203 FORMAT(1x,'Civ. Labor Force ',4(5x,f8.0)/' (thousands of persons)'/)
204 FORMAT(1x,'Corporate Profits ',4(5x,f8.0)/' (millions of $)'/)
205 FORMAT(1x,'Total Population ',4(5x,f8.0)/' (thousands of persons)'/)
!
! Use the WRITE command to write out the table. Note that to prevent
! the echoing of the WRITE commands in between the output, disable the
! ECHO option with the OFF ECHO command.
!
OFF ECHO
WRITE(200)
WRITE(201) year
WRITE(202) gnp
WRITE(203) clf
WRITE(204) profits
WRITE(205) total_population
ON ECHO
!
! If this table had been written to disk, it would have been
! written with the command:
!
! WRITE(filename 200)
! WRITE(filename 201) year
! WRITE(filename 202) gnp
! WRITE(filename 203) clf
! WRITE(filename 204) profits
! WRITE(filename 205) total_population
!
! The table would reside in the file "filename.lst".
!
! Formatted data can be written to the terminal or file in column-wise
! organization. To do this, enclose the variable list in parentheses.
! For example, if you wanted to write "year", "gnp", "clf" and "profits"
! in the same format as the table that was input, the command would be:
!
! WRITE(filename 100) (year gnp clf profits)
!
!
!
!*******************************************************************!
! !
! SORITEC Sampler Databanking Commands !
! (Chapter 4) !
! !
!*******************************************************************!
!
! SORITEC databanks are the key to using Sampler efficiently. Databanks
! can store data series, equations, matrices, vectors, parameters,
! GROUPS and even entire models in the full version of SORITEC.
! SORITEC databanks are created, managed and deleted entirely within
! SORITEC Sampler. In your DOS directory, they are identified by
! the extension, "SDB". This section of the demonstration illustrates
! the capabilities of the SORITEC Sampler's databanking facility.
!
! Data banks are created with the CREATE command (but first we'll
! attempt to PURGE it in case it already exists), e.g.,
!
PURGE 'a:ecdata'
!
! Don't worry about the message if the file was not found.
!
CREATE 'a:ecdata'
!
! Note that when redirecting output to another drive or directory,
! the filename must be enclosed within single quotes. Otherwise,
! simply enter the filename. In out example, we should now have a
! databank file named "ecdata.sdb" on the a: drive. Note that
! the "SDB" extension is not included with the file name in the
! command line. Databank names must be 8 characters or less to conform
! to DOS naming conventions.
!
! You save data in a databank with the KEEP command. For example,
! to save "gnp", "clf", and "profits" data that we used earlier,
! enter:
!
KEEP gnp clf profits
!
! To verify the contents of the databank you have currently attached,
! enter the CONTENTS command, e.g.,
!
CONTENTS
!
! KEEP saves all observations associated your data series regardless
! of the currently active USE period. If you want to save only the
! active observations, you must enter the keyword ACTIVE as a
! modifier to the command. For example, suppose we want to save
! only the 1982 and 1983 values of "pop_difference" and
! "female_proportion" in "ecdata". Then change the USE period to
! the 1982 to 1983 period, and then KEEP them with the ACTIVE
! modifier included in the command line.
!
USE 1982 1983
KEEP(ACTIVE) pop_difference female_proportion
!
! Only the observations for 1982 and 1983 will be saved.
!
! Note that once we have these variables in the databank, we can
! remove them from SORITEC Sampler's symbol table with the FORGET
! command, e.g.,
!
FORGET pop_difference female_proportion
!
! If you type SYMBOLS, you will note that these two variables are not
! longer in Sampler's workspace. While we have them in the "ecdata"
! databank, we only have the observations for 1982 and 1983. Previous
! observations are lost, once cleared from the workspace.
!
! You can explicitly detach a SORITEC databank from your job session
! with the RETURN command. For example,
!
RETURN
!
! closes "ecdata.sdb" and detaches it from SORITEC Sampler. Databanks
! are automatically returned when you CREATE a new databank or access
! an existing one.
!
! If you want to attach an existing databank, you ACCESS it, e.g.,
!
ACCESS 'a:ecdata'
!
! You can implicitly access a databank with the CONTENTS command. For
! example, "CONTENTS ecdata" would return any attached databank, access
! the named databank and produce a listing of variables it contains.
!
! Let's demonstrate some the the things that can be stored in SORITEC
! Sampler's databanks. To do this, we'll create a databank on the "a:"
! drive to store population-related information. Again, we'll attemp
! to PURGE it in case it already exists.
!
PURGE 'a:popdata'
!
! If the file does not already exist, you will receive a message.
!
CREATE 'a:popdata'
!
! Let's define a GROUP to reference the three annual population variables
! that we started out with in this demonstration, "total_population",
! "male_population" and "female_population".
!
GROUP pop_group total_population male_population female_population
!
! Print out the data after restoring the original USE period.
!
USE 1978 1983
ON GROUP
PRINT pop_group
!
! We can use the GROUP definition to store all population data in a
! single command with one argument, e.g.,
!
KEEP pop_group
!
! Now if you think you might want to refer to these three population
! variables as a group later, store the GROUP definition, as well,
! by first turning OFF the group expansion option and then KEEPing
! the GROUP.
!
OFF GROUP
KEEP pop_group
!
! The next time you want to go into this databank, simply retrieve the
! GROUP with the group expansion option turned off, enable group expansion
! with the ON GROUP command and then copy the data from the databank by
! refering to the GROUP definition.
!
! SORITEC Sampler can also store equations. Since we lost some
! observations for "pop_difference" and "female_proportion" because
! we chose only to store the ACTIVE observations, let's define
! equations for the two variables and store the equations in
! the "popdata.sdb" databank so that we can recreate the data from
! the other variables in the databank.
!
! First, define the equations:
!
equation pop_dif pop_difference = female_population - male_population
equation fem_prop female_proportion = female_population/total_population
!
! and then KEEP them.
!
KEEP pop_dif fem_prop
!
! You can similarly store vectors, parameters, constants and matrices
! generated by Sampler. Remember that since Sampler does not support
! matrix operations generally, the only matrices you'll be able to
! store are those generated by the various estimation commands and
! the XTAB command.
!
! Let's forget everything from Sampler's workspace since all the
! important information is now in the two databanks.
!
FORGET *
!
! Several other utilities are available to manage items in your
! databanks. To show these let's ACCESS "ecdata.sdb" from the a:drive.
!
ACCESS 'a:ecdata'
CONTENTS
!
! Suppose we want to rename items in a databank. This is done with the
! RENAME command. For example, to rename "gnp" to "gnp_in_current_dos"
! the command would be:
!
USE 1980 1983
RENAME gnp_in_current_dollars gnp
!
! Note the argument order in this command: RENAME new_name old_name
!
! For practice, we'll rename the other two economic items, clf and
! profits so that their units are identified with the variable name.
!
RENAME profits_mil_of_dols clf
RENAME clf_thous_pers profits
!
! Whoops! We assigned the wrong names to the two variables. Oh well,
! this is a good time to demonstrate the SWITCH command, which allows
! you to switch the names of two variables.
!
SWITCH profits_mil_of_dols clf_thous_pers
!
! Now the correct names will be associated with the proper data.
! One important thing to remember about renaming or switching the
! names of items in databanks. If you change the name of an item
! and that item is also defined in a GROUP, the group definition
! is NOT automatically updated and you will be unable to reference
! the data from the original group definition.
!
!
! Retrieving items from a databank is even easier than saving them.
! You can either COPY them explicitly or simply reference them in
! a legal SORITEC Sampler command. If Sampler cannot find the item
! in its workspace it automatically searches any attached databank
! to see if it exists there. If it does, the item is copied to the
! workspace and used as required.
!
! The copy command is simply:
!
COPY profits_mil_of_dols clf_thous_pers
!
! Let's make sure the item names are associated with the right data.
!
PRINT profits_mil_of_dols clf_thous_pers
!
! Note that these items are now back in Sampler's workspace.
!
SYMBOLS
!
! We could have just as easily printed the data without explicitly
! copying it as shown for gnp_in_current_dollars
!
PRINT gnp_in_current_dollars
!
! And notice that it, too, is now back in the workspace.
!
SYMBOLS
!
! If you want to delete items from an attached databank, use the DISCARD
! command. For example, suppose we want to store "pop_difference" and
! "female_proportion" in the "popdata.sdb" databank. Let's first copy
! the values for "pop_difference" and "female_proportion" into the
! workspace for future use.
!
COPY pop_difference female_proportion
!
! Then DISCARD the unwanted items.
!
DISCARD pop_difference female_proportion
!
! To check, type CONTENTS, and Voila!
!
CONTENTS
!
! We'll access "popdata.sdb" now to complete the transfer of information.
!
ACCESS 'a:popdata'
!
! Note that "ecdata.sdb" will be automatically RETURNed with this command.
!
! Now KEEP the two population variables.
!
KEEP pop_difference female_proportion
!
! But wait, there are only data for 1982 and 1983.
!
PRINT pop_difference female_proportion
!
! We should re-generate the 1978 to 1981 values with the equations
! we stored earlier. Let's check to see what we have stored
! in the databank.
!
CONTENTS
!
! We'll retrieve the two equations and the GROUP definition, but will
! let Sampler implicitly copy the data series when they are referenced
! in equation computations.
!
COPY pop_dif fem_prop pop_group
!
! Equations and group definitions are printible, so let's take a look.
!
PRINT pop_dif fem_prop pop_group
!
! Check the USE period to make sure we are computing over the appropriate
! period. Note that SORITEC Sampler makes no assumptions about the USE
! period when it copies an item from a databank. For data series and any
! other multiple element data type that is stored, Sampler copies all
! observations regardless of active USE period. If no USE period is
! defined, it will still copy all observations, but you will not be able
! to do anything with the data, such as PRINT it, etc. until a valid
! USE period is defined.
!
USE
!
! We'll change the period to 1978 to 1981 and REVISE the two series so
! they incorporate all four observations.
!
USE 1978 1981
ON REVISE
!
! Equations and identities are calculated with the COMPUTE command.
!
COMPUTE pop_dif
COMPUTE fem_prop
!
! Disable the data revision option.
!
OFF REVISE
!
! Print out the values for 1978 to 1983.
!
USE 1978 1983
PRINT pop_difference female_proportion
!
! Now save the items in the databank. Note, however, if you try to
! KEEP a data item that currently exists in the databank, you get
! an error message and the new data are not saved.
!
KEEP pop_difference female_proportion
!
! Instead, you must REPLACE the data item, either with the REPLACE
! command, e.g.
!
REPLACE pop_difference
!
! or KEEP the item with the ON REPLACE option enabled.
!
ON REPLACE
KEEP female_proportion
OFF REPLACE
!
! Everything should now be set in our databank.
!
CONTENTS
!
! To make sure that the two revised variables were replaced correctly,
! first clear the workspace and then print the items.
!
FORGET pop_difference female_proportion
SYMBOLS
PRINT pop_difference female_proportion
!
! The only thing left to show is how to delete your databanks from
! within SORITEC Sampler. This is done with the PURGE command. After
! the two databanks we created are purged, this demonstration is over.
!
PURGE 'a:popdata'
PURGE 'a:ecdata'
cls
QUIT